package org.fhawk.tinyspring.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by tuo on 8/17/2016.
 */
public class ObjectUtil {
    private static final Logger logger = LoggerFactory.getLogger(ObjectUtil.class);

    private ObjectUtil() {
    }

    /**
     * 根据名称 获取实例
     *
     * @param className
     * @param <T>
     * @return
     */
    public static <T> T newInstance(String className) {
        T instance = null;
        try {
            Class<?> clazz = ClassUtil.loadClass(className);
            instance = (T) clazz.newInstance();
        } catch (Exception e) {
            logger.error("get new instance error", e);
        }
        return instance;
    }

    /**
     * 强转
     *
     * @param clazz
     * @param o
     * @param <T>
     * @return
     */
    public static <T> T cast(Class<T> clazz, Object o) {
        return clazz.cast(o);
    }
}
